package com.hjh.gameforum.controller;

import com.hjh.gameforum.dto.ReplyDto;
import com.hjh.gameforum.dto.ReplyQueryParem;
import com.hjh.gameforum.entity.Reply;
import com.hjh.gameforum.entity.Topic;
import com.hjh.gameforum.result.PageResult;
import com.hjh.gameforum.result.Result;
import com.hjh.gameforum.service.ReplyService;
import com.hjh.gameforum.vo.ReplyVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/replies")
@RequiredArgsConstructor
@Tag(name = "评论管理", description = "评论相关操作")
@Slf4j
public class ReplyController {

    private final ReplyService replyService;

    @PostMapping
    @Operation(summary = "创建评论")
    public Result createReply(@RequestBody ReplyDto replyDto) {
        log.info("创建评论：{}", replyDto);
        replyService.createReply(replyDto);
        return Result.success();
    }

    @GetMapping
    @Operation(summary = "分页获取评论列表")
    public Result getReplyList(
            @RequestParam(required = false) Long topicId,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("分页获取评论列表 - topicId:{}, page:{}, pageSize:{}", topicId, page, pageSize);
        ReplyQueryParem param = new ReplyQueryParem(topicId, page, pageSize);
        PageResult<ReplyVo> replys = replyService.getReplyList(param);
        return Result.success(replys);
    }

    @PutMapping("/like/{id}")
    @Operation(summary = "点赞评论")
    public Result likeReply(@PathVariable Integer id) {
        log.info("点赞评论 - id:{}", id);
        replyService.likeReply(id);
        return Result.success();
    }

    @DeleteMapping("/like/{id}")
    @Operation(summary = "取消点赞评论")
    public Result unlikeReply(@PathVariable Integer id) {
        log.info("取消点赞评论 - id:{}", id);
        replyService.unlikeReply(id);
        return Result.success();
    }
    @GetMapping("/like/{id}")
    @Operation(summary = "获取用户是否点赞评论")
    public Result<Boolean> getLikeStatus(@PathVariable Integer id) {
        log.info("获取用户是否点赞评论 - id:{}", id);
        boolean likeStatus = replyService.getLikeStatus(id);
        return Result.success(likeStatus);
    }

}
